package com.lsk.weixin;

import com.jfinal.weixin.iot.msg.InEquDataMsg;
import com.jfinal.weixin.iot.msg.InEqubindEvent;
import com.jfinal.weixin.sdk.api.ApiResult;
import com.jfinal.weixin.sdk.api.MenuApi;
import com.jfinal.weixin.sdk.jfinal.MsgController;
import com.jfinal.weixin.sdk.msg.in.*;
import com.jfinal.weixin.sdk.msg.in.card.*;
import com.jfinal.weixin.sdk.msg.in.event.*;
import com.jfinal.weixin.sdk.msg.in.speech_recognition.InSpeechRecognitionResults;
import com.jfinal.weixin.sdk.msg.out.OutTextMsg;
import com.lsk.util.AES;
import com.lsk.util.Syslog;

/**
 * Created by Administrator on 2018/9/7 0007.
 */
public class WeiXinController extends MsgController {

    WeiXinService weiXinService=new WeiXinService();
    OutTextMsg outTextMsg=new OutTextMsg();

    public OutTextMsg structureOutTextMsg(){
        outTextMsg.setContent("感谢您的信任，如有问题请联系：13083690563");
        outTextMsg.setCreateTime((int) System.currentTimeMillis());
        return outTextMsg;
    }

    @Override
    protected void processInTextMsg(InTextMsg inTextMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inTextMsg.getToUserName());
        outTextMsg.setToUserName(inTextMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInImageMsg(InImageMsg inImageMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inImageMsg.getToUserName());
        outTextMsg.setToUserName(inImageMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInVoiceMsg(InVoiceMsg inVoiceMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inVoiceMsg.getToUserName());
        outTextMsg.setToUserName(inVoiceMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInVideoMsg(InVideoMsg inVideoMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inVideoMsg.getToUserName());
        outTextMsg.setToUserName(inVideoMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInShortVideoMsg(InShortVideoMsg inShortVideoMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inShortVideoMsg.getToUserName());
        outTextMsg.setToUserName(inShortVideoMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInLocationMsg(InLocationMsg inLocationMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inLocationMsg.getToUserName());
        outTextMsg.setToUserName(inLocationMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInLinkMsg(InLinkMsg inLinkMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inLinkMsg.getToUserName());
        outTextMsg.setToUserName(inLinkMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInCustomEvent(InCustomEvent inCustomEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inCustomEvent.getToUserName());
        outTextMsg.setToUserName(inCustomEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInFollowEvent(InFollowEvent inFollowEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inFollowEvent.getToUserName());
        outTextMsg.setToUserName(inFollowEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInQrCodeEvent(InQrCodeEvent inQrCodeEvent) {
        Syslog.info("扫描二维码事件");
        String str=weiXinService.processInQrCodeEventService(inQrCodeEvent);
        Syslog.info(str);
        renderText(str);
    }

    @Override
    protected void processInLocationEvent(InLocationEvent inLocationEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inLocationEvent.getToUserName());
        outTextMsg.setToUserName(inLocationEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInMassEvent(InMassEvent inMassEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inMassEvent.getToUserName());
        outTextMsg.setToUserName(inMassEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInMenuEvent(InMenuEvent inMenuEvent) {
        Syslog.info(inMenuEvent.toString());
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inMenuEvent.getToUserName());
        outTextMsg.setToUserName(inMenuEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInSpeechRecognitionResults(InSpeechRecognitionResults inSpeechRecognitionResults) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inSpeechRecognitionResults.getToUserName());
        outTextMsg.setToUserName(inSpeechRecognitionResults.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInTemplateMsgEvent(InTemplateMsgEvent inTemplateMsgEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inTemplateMsgEvent.getToUserName());
        outTextMsg.setToUserName(inTemplateMsgEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInShakearoundUserShakeEvent(InShakearoundUserShakeEvent inShakearoundUserShakeEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inShakearoundUserShakeEvent.getToUserName());
        outTextMsg.setToUserName(inShakearoundUserShakeEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInVerifySuccessEvent(InVerifySuccessEvent inVerifySuccessEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inVerifySuccessEvent.getToUserName());
        outTextMsg.setToUserName(inVerifySuccessEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInVerifyFailEvent(InVerifyFailEvent inVerifyFailEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inVerifyFailEvent.getToUserName());
        outTextMsg.setToUserName(inVerifyFailEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInPoiCheckNotifyEvent(InPoiCheckNotifyEvent inPoiCheckNotifyEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inPoiCheckNotifyEvent.getToUserName());
        outTextMsg.setToUserName(inPoiCheckNotifyEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInWifiEvent(InWifiEvent inWifiEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inWifiEvent.getToUserName());
        outTextMsg.setToUserName(inWifiEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInUserCardEvent(InUserCardEvent inUserCardEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inUserCardEvent.getToUserName());
        outTextMsg.setToUserName(inUserCardEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInUpdateMemberCardEvent(InUpdateMemberCardEvent inUpdateMemberCardEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inUpdateMemberCardEvent.getToUserName());
        outTextMsg.setToUserName(inUpdateMemberCardEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInUserPayFromCardEvent(InUserPayFromCardEvent inUserPayFromCardEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inUserPayFromCardEvent.getToUserName());
        outTextMsg.setToUserName(inUserPayFromCardEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInMerChantOrderEvent(InMerChantOrderEvent inMerChantOrderEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inMerChantOrderEvent.getToUserName());
        outTextMsg.setToUserName(inMerChantOrderEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processIsNotDefinedEvent(InNotDefinedEvent inNotDefinedEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inNotDefinedEvent.getToUserName());
        outTextMsg.setToUserName(inNotDefinedEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processIsNotDefinedMsg(InNotDefinedMsg inNotDefinedMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inNotDefinedMsg.getToUserName());
        outTextMsg.setToUserName(inNotDefinedMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInUserGiftingCardEvent(InUserGiftingCardEvent inUserGiftingCardEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inUserGiftingCardEvent.getToUserName());
        outTextMsg.setToUserName(inUserGiftingCardEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInUserGetCardEvent(InUserGetCardEvent inUserGetCardEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inUserGetCardEvent.getToUserName());
        outTextMsg.setToUserName(inUserGetCardEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInUserConsumeCardEvent(InUserConsumeCardEvent inUserConsumeCardEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inUserConsumeCardEvent.getToUserName());
        outTextMsg.setToUserName(inUserConsumeCardEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInCardSkuRemindEvent(InCardSkuRemindEvent inCardSkuRemindEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inCardSkuRemindEvent.getToUserName());
        outTextMsg.setToUserName(inCardSkuRemindEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInCardPayOrderEvent(InCardPayOrderEvent inCardPayOrderEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inCardPayOrderEvent.getToUserName());
        outTextMsg.setToUserName(inCardPayOrderEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInCardPassCheckEvent(InCardPassCheckEvent inCardPassCheckEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inCardPassCheckEvent.getToUserName());
        outTextMsg.setToUserName(inCardPassCheckEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInEqubindEvent(InEqubindEvent inEqubindEvent) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inEqubindEvent.getToUserName());
        outTextMsg.setToUserName(inEqubindEvent.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    @Override
    protected void processInEquDataMsg(InEquDataMsg inEquDataMsg) {
        outTextMsg=structureOutTextMsg();
        outTextMsg.setFromUserName(inEquDataMsg.getToUserName());
        outTextMsg.setToUserName(inEquDataMsg.getFromUserName());
        renderText(outTextMsg.toXml());
    }

    public void createMenu(){
        String str= AES.AESDncode(getPara("content"));
        ApiResult apiResult=MenuApi.createMenu(str);
        renderJson(apiResult);
    }
}
